unit dbcSQL_Exec;
// Database Comparer VCL v.3.0
// Copyright (C) 1998-2006, by Boris Loboda
// www.CleverComponents.com
{$I Comparer.INC}

// Update script executing
//
// History:
// 27.07.2005
// - ExecuteScript, BlobFile support.

interface

Uses SysUtils, Classes, DB,
     {$IFDEF Delphi6} Variants,{$ENDIF}
     dbcClasses, dbcTypes,
     dbcDBOptions, dbcDBEngine;

type
  // SQL Executive - save statements sequence and only show update script
  // for update target database - use database specicific SQLExec
  // TSQLExec use internally into TDBComparer, if not assigned SQLExec property
  TSQLExec = Class(TCustomSQLExec)
  protected
    fConnectionOptions: TConnectionOptions;
    fIBServerOptions: TIBServerOptions;
    fMSSQLServerOptions: TMSSQLServerOptions;
    fMySQLServerOptions: TMySQLServerOptions;
    fASAServerOptions: TASAServerOptions;
    fASEServerOptions: TASEServerOptions;
    fOracleServerOptions: TOracleServerOptions;
    fPGSQLServerOptions: TPGSQLServerOptions;
    fDB2ServerOptions: TDB2ServerOptions;
    fQuery: TDBCQuery;
    fBlobFileName: TFileName;
    fBlobStream: TFileStream;
    fMemStream: TMemoryStream;
    fConnection: TDBCCustomConnection;
    fStatement: TStatement;
    fOnGetParamValue: TGetParamValueEvent;
    function QuoteIdent(aIdent: String): String; virtual;
    procedure SetConnection(aConnection: TDBCCustomConnection); virtual;
    procedure Notification(aComponent: TComponent; Operation: TOperation); override;
    function UpdateDescription(): Boolean; virtual;
    function AcceptBlobParams(): Boolean; virtual;
    function RunConnect(): Boolean; virtual;
    function RunReConnect(): Boolean; virtual;
    function RunCreateDb(): Boolean; virtual;
    function RunDescription(): Boolean; virtual;
    function RunSetBlobFile(): Boolean; virtual;
    function RunInsertUpdateDelete(): Boolean; virtual;
    function RunStatement(): Boolean; virtual;
    function CreateParser(aObjs: TCustomObjs): TObject; virtual;
    procedure DoErrorMessage(ErrMsg: String); override;
    procedure DoGetParamValue(Param: TParam); virtual;
    procedure SetIBServerOptions(aOptions: TIBServerOptions);
    procedure SetMSSQLServerOptions(aOptions: TMSSQLServerOptions);
    procedure SetMySQLServerOptions(aOptions: TMySQLServerOptions);
    procedure SetASAServerOptions(aOptions: TASAServerOptions);
    procedure SetASEServerOptions(aOptions: TASEServerOptions);
    procedure SetOracleServerOptions(aOptions: TOracleServerOptions);
    procedure SetPGSQLServerOptions(aOptions: TPGSQLServerOptions);
    procedure SetDB2ServerOptions(aOptions: TDB2ServerOptions);
  public
    constructor Create(aOwner: TComponent); override;
    destructor Destroy; override;
    // Execute script (Connect - if need)
    function ExecuteScript(): Boolean; override;
    // Connect / execute statement / disconnect
    procedure ExecuteStatement(st: TStatement); override;
    // execute statement (DBCConnection.Active = True)
    function ExecStatement(statement: TStatement): Boolean; virtual;
    procedure Clear; override;
    procedure Add_Commit(); override;
    // add comment-statement
    function AddComment(Comment: String): TStatement; override;
    procedure AddReConnect(); override;
    // generate text script from statements sequence
    procedure GetScript(sList: TStrings; LineReNumber: Boolean = True); override;
    property ConnectionOptions: TConnectionOptions
                                read fConnectionOptions;
    property IBServerOptions: TIBServerOptions
                              read fIBServerOptions
                              write SetIBServerOptions;
    property MSSQLServerOptions: TMSSQLServerOptions
                                 read fMSSQLServerOptions
                                 write SetMSSQLServerOptions;
    property MySQLServerOptions: TMySQLServerOptions
                                 read fMySQLServerOptions
                                 write SetMySQLServerOptions;
    property ASAServerOptions: TASAServerOptions
                                  read fASAServerOptions
                                  write SetASAServerOptions;
    property ASEServerOptions: TASEServerOptions
                                  read fASEServerOptions
                                  write SetASEServerOptions;
    property OracleServerOptions: TOracleServerOptions
                                  read fOracleServerOptions
                                  write SetOracleServerOptions;
    property PGSQLServerOptions: TPGSQLServerOptions
                                  read fPGSQLServerOptions
                                  write SetPGSQLServerOptions;
    property DB2ServerOptions: TDB2ServerOptions
                                  read fDB2ServerOptions
                                  write SetDB2ServerOptions;
    property ScriptFileName: TFileName read fScriptFileName write fScriptFileName;
    property BlobFileName: TFileName read fBlobFileName write fBlobFileName;
    property DBCConnection: TDBCCustomConnection read fConnection write SetConnection;
  published
    property OnLoadScript;
    property OnGetParamValue: TGetParamValueEvent
                              read fOnGetParamValue
                              write fOnGetParamValue;
  end;

implementation

//The full source code is available on purchasing the product

end.
